function ServerSocket (socket) {
  this._s = this.socket = socket
  this.bindingEvents()
}

ServerSocket.prototype = {
  bindingEvents () {
    let _s = this.socket
    _s.on('create_room', this.createRoom.bind(this))
    _s.on('join_room', this.joinRoom.bind(this))
  },
  createRoom (msg) {
    let roomName = `room_${msg.id}`
    this._s.join(roomName)
    console.log('created room ' + roomName)
    this.notifyRoomJoined(roomName)
  },
  joinRoom (msg) {
    let {roomName} = msg
    this._s.join(roomName)
    console.log('join room ' + roomName)
    this.notifyRoomJoined(roomName)
  },
  notifyRoomJoined (roomName) {
    this._s.emit('room_joined', {
      roomName
    })
  }
}

module.exports = exports = {
  ServerSocket
}